package test.exact;

import bean.Task;
import bean.Worker;
import util.greedy.ArgMax;
import util.greedy.GSatisfy;

import java.util.HashSet;
import java.util.Iterator;

public class Exact {
    /**
     * Top-1 贪心算法
     * @param workers 工人集合
     * @param task 一个任务
     * @return team组建好的团队
     */
    public static HashSet<Worker> exact(HashSet<Worker> workers, Task task) {

        HashSet<Worker> team = new HashSet<>();
        while ( !GSatisfy.isGSatisfy(team,task.getSkills()) ) { /*因为这个循环是死循环，所以程序停不下来*/
            HashSet<Worker> teamBreak = new HashSet<>();
            Iterator<Worker> iteratorWorkers = workers.iterator();
            while ( iteratorWorkers.hasNext() ) {
                teamBreak.add(iteratorWorkers.next());
            }

            if ( !GSatisfy.isGSatisfy(teamBreak,task.getSkills()) ) {
                break;
            }

            Worker workerNew = new Worker();
            workerNew = ArgMax.argMax(workers,task,team);
            if (workerNew != null){
                team.add(workerNew);
            }
        }
        for (Worker w : team) {
            System.out.println(w);
        }
        System.out.println("=====================");
        return team;
    }
}
